package capricornus.actor.controller
{
	import capricornus.actor.Actor;
	import capricornus.actor.attribute.CharacterAttribute;
	import capricornus.actor.events.ActorAttributeEvent;
	import capricornus.actor.res.ActionImageController;
	
	import flash.display.Bitmap;
	
	/**
	 * 角色图象控制器
	 * 注：比ActorImageController复杂点，处理武器、坐骑等 
	 * @author Administrator
	 * 
	 */	
	public class CharacterImageController extends ActorImageController
	{
		protected var _weaponImageController:ActionImageController;             //武器
		private var _mountImageController:ActionImageController;              //坐骑
		
		public function CharacterImageController(actor:Actor)
		{
			super(actor);
			init();
		}
		
		private function init():void
		{
			_weaponImageController = new ActionImageController( (_attribute as CharacterAttribute).weaponActionImagePath );
			_mountImageController = new ActionImageController( (_attribute as CharacterAttribute).mountActionImagePath );
			
			_actor.imageContainer.addChild( _weaponImageController.bitmap );
			_actor.imageContainer.addChild( _mountImageController.bitmap );
			
			_attribute.addEventListener( ActorAttributeEvent.WEAPON_ACTION_IMAGE_PATH_CHANGED, onWeaponActionImagePathChanged, false, 0, true );
			_attribute.addEventListener( ActorAttributeEvent.MOUNT_ACTION_IMAGE_PATH_CHANGED, onMountActionImagePathChanged, false, 0, true );
		}
		
		override public function set direction(value:int):void
		{
			super.direction = value;
			//不同的方向，武器、坐骑、人物的显示层级不一样
		}
		
		override protected function nextFrame( frameTime:uint ):void
		{
			_weaponImageController.nextFrame( _direction, _currentFrame );
			_mountImageController.nextFrame( _direction, _currentFrame );
			super.nextFrame( frameTime );
		}
		
		private function onWeaponActionImagePathChanged( e:ActorAttributeEvent ):void
		{
			_weaponImageController.actionImageName = (_attribute as CharacterAttribute).weaponActionImagePath
		}
		
		private function onMountActionImagePathChanged( e:ActorAttributeEvent ):void
		{
			_mountImageController.actionImageName = (_attribute as CharacterAttribute).mountActionImagePath
		}
	}
}